home *** CD-ROM | disk | FTP | other *** search
- /*
- This file is a fairly generic event handler for an XFun with a single window.
- It calls DrawPlot() on update and assumes globals myWindow and myCursor have been set.
- */
-
- #include "callbackg.h"
- #include "XFundef.h"
-
- static int checkcursor(void) // called whenever cursor region may have changed
- {
- Rect inside;
- RgnHandle inrgn;
-
- if(FrontWindow() != myWindow) return(FALSE);
-
- inside = myWindow->portRect;
- inside.right-=15;
- inside.bottom-=15; // assume space for scroll bars
- SetPort(myWindow);
- LocalToGlobal(&topLeft(inside));
- LocalToGlobal(&botRight(inside));
- inrgn = NewRgn();
- RectRgn(inrgn,&inside);
- SetCursorRegion(*myCursor,inrgn);
- DisposeRgn(inrgn);
- return(TRUE);
- }
-
- static int DoMouseDown(EventRecord *theEvent)
- {
- WindowPtr theWindow;
- int partCode;
- long size;
- Rect sizeLimit;
- GrafPtr oldPort;
-
- partCode = FindWindow(theEvent->where,&theWindow);
- /* to intercept menu events
- if(partCode == inMenuBar)
- {
- selector = MenuSelect(theEvent->where);
- if(mymenu(selector)) return(TRUE);
- DoMenuItem(selector);
- return(FALSE);
- }
- */
- if(theWindow != myWindow) return(FALSE);
-
- // reach here only if MouseDown was in myWindow
- switch(partCode)
- {
- case inDrag:
- SelectWindow(theWindow);
- SetRect(&sizeLimit,0,25,4000,4000);
- DragWindow(theWindow,theEvent->where,&sizeLimit);
- checkcursor();
- break;
-
- case inContent:
- if(theWindow != FrontWindow())
- {
- SelectWindow(theWindow);
- break;
- }
- /* handle click in window
- GetPort(&oldPort);
- SetPort(theWindow);
- ...
- SetPort(oldPort);
- */
- break;
-
- case inGoAway:
- if(TrackGoAway(theWindow,theEvent->where))
- {
- HideWindow(theWindow);
- }
- break;
-
- case inGrow:
- SetRect(&sizeLimit,150,70,1000,1000);
- size = GrowWindow(theWindow,theEvent->where,&sizeLimit);
- if(size)
- {
- GetPort(&oldPort);
- SetPort(theWindow);
- EraseRect(&theWindow->portRect);
- InvalRect(&theWindow->portRect);
- SizeWindow(theWindow,LoWord(size),HiWord(size),TRUE);
- DrawGrowIcon(theWindow);
- SetPort(oldPort);
- }
- break;
-
- case inZoomIn:
- case inZoomOut:
- if(TrackBox(theWindow,theEvent->where,partCode))
- {
- GetPort(&oldPort);
- SetPort(theWindow);
- ZoomWindow(theWindow,partCode,FALSE);
- InvalRect(&theWindow->portRect);
- DrawGrowIcon(theWindow);
- SetPort(oldPort);
- }
- break;
- }
- return(TRUE);
- }
-
- static void Update(void)
- {
- GrafPtr oldPort;
- GetPort(&oldPort);
- SetPort(myWindow);
- BeginUpdate(myWindow);
- EraseRect(&myWindow->portRect);
- DrawPlot();
- DrawGrowIcon(myWindow);
- EndUpdate(myWindow);
- checkcursor(); /* any change in window size generates an update */
- SetPort(oldPort);
- }
-
- static void activate(void)
- {
- SelectWindow(myWindow);
- DrawGrowIcon(myWindow);
- }
-
- static void deactivate(void)
- {
- DrawGrowIcon(myWindow);
- }
-
- /* handle messages from MathPad */
- static void MPmessage(long msg)
- {
- /*
- switch(msg)
- {
- case DOCSAVED:
- break;
-
- case DOCCLOSE:
- break;
- ...
- }
- */
- }
-
- short doevent(EventRecord *theEvent)
- {
- switch (theEvent->what)
- {
- case mouseDown:
- return DoMouseDown(theEvent);
-
- case updateEvt:
- if(myWindow == (WindowPtr)(theEvent->message))
- {
- Update();
- return(TRUE);
- }
- break;
-
- case activateEvt:
- if(myWindow == (WindowPtr)(theEvent->message))
- {
- if(theEvent->modifiers & activeFlag)
- activate();
- else
- deactivate();
- return(TRUE);
- }
- break;
-
- case app3Evt:
- MPmessage(theEvent->message);
- break;
-
- case app4Evt:
- if((theEvent->message & 0xFF000000) == 0x01000000)
- {
- if(theEvent->message & 1) /* resume */
- {
- if(myWindow == FrontWindow()) activate();
- }
- else /* suspend */
- {
- deactivate();
- }
- return(FALSE); /* MathPad needs to do further processing */
- }
- else
- if((theEvent->message & 0xFF000000) == 0xFA000000) /* mouse moved */
- return(checkcursor());
- break;
-
- }
- return(FALSE);
- }
-
-